#pragma once
#include <string>
#include <iostream>
#include "fabuzhe.h"
using namespace std;

// 抽象的订阅者类
class Observer
{
public:
    Observer(string name, fabuzzhe* news) :m_name(name), m_news(news)
    {
        m_news->attach(this);
    }
    void unsubscribe()
    {
        m_news->detach(this);
    }
    virtual void update(string msg) = 0;
    virtual ~Observer() {}
protected:
    string m_name;
    fabuzzhe* m_news;
};

class Observer1 : public Observer
{
public:
    using Observer::Observer;
    void update(string msg) override
    {
        cout << "Observer1收到消息: " << msg << endl;
    }
};

class Observer2: public Observer
{
public:
    using Observer::Observer;
    void update(string msg) override
    {
        cout << "Observer2收到消息: " << msg << endl;
    }
};